package com.boss.salary.service.impl;

import com.boss.salary.dao.IPersonTypeSalaryDao;
import com.boss.salary.entity.PersonTypeSalary;
import com.boss.salary.service.IPersonTypeSalaryService;
import com.boss.sys.ca.user.dto.UserDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class PersonTypeSalaryServiceImpl implements IPersonTypeSalaryService {

    @Autowired
    private IPersonTypeSalaryDao personTypeSalaryDao;
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void savePersonTypeSalary(PersonTypeSalary personTypeSalary, UserDTO userDTO) {
        personTypeSalary.setMofDivCode(userDTO.getProvince());
        personTypeSalaryDao.savePersonTypeSalary(personTypeSalary);
    }

    @Override
    public void updatePersonTypeSalary(PersonTypeSalary personTypeSalary, UserDTO userDTO) {

    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void batchSavePersonTypeSalary(List<PersonTypeSalary> personTypes, UserDTO userDTO)  throws Exception  {
        Map<String, Object> queryParam=new HashMap<>();
        queryParam.put("mof_div_code",userDTO.getProvince());
        if(!CollectionUtils.isEmpty(personTypes)) {
            queryParam.put("personTypeCode",personTypes.get(0).getPersonTypeCode());
        }else{
            throw new Exception("未识别到人员类型，无法清除挂接工资项信息");
        }
        personTypeSalaryDao.physicsDeletePersonTypeSalary(queryParam);
        personTypeSalaryDao.batchSavePersonTypeSalary(personTypes,userDTO.getProvince());

    }

    @Override
    public List<PersonTypeSalary> getInfoByPersonTypes(List<String> personTypes, UserDTO userDTO) {
        return personTypeSalaryDao.getInfoByPersonTypes(personTypes,userDTO.getProvince());
    }


    @Override
    public List<Map<String, Object>> getAllPersonTypeByProvince(UserDTO userDTO) {
        return personTypeSalaryDao.getAllPersonTypeByProvince(userDTO.getProvince());
    }
}
